/*
 * @Author: askMeWhy
 * @Date:   2018-07-05 09:57:40
 * @Last Modified by: AskMeWhy
 * @Last Modified time: 2021-02-24 15:31:51
 */
import { sessionStorage } from "../utils/storage";
// const url = "http://192.168.1.101:9290/saas-api"; // 测试
// const url = "http://192.168.10.79:9290/saas-api"; // 薛通建
// const url = "http://192.168.1.24:9290/saas-api"; // 章贵敏
// const url = "http://192.168.1.5:9290/saas-api"; // 赵景驰
// const authUrl = "http://192.168.1.9:9290/saas-api";
// const url = "https://app.tianzuoyun.com/api/cms";
const staticUrl =
    "https://tianzuoyun-test-1304386495.cos.ap-chengdu.myqcloud.com";
// const staticUrl = "https://tianzuoyun-pro-1304386495.cos.ap-chengdu.myqcloud.com";
const wsUrl = "ws://192.168.1.101:9290/saas-api/third/websocket/";

const isDev = process.env.NODE_ENV === "development";
export const apiList = [
    { name: "测试", url: "http://192.168.1.101:9290/saas-api" },
    { name: "薛通建", url: "http://192.168.100.131:9290/saas-api" },
    { name: "赵景驰", url: "http://192.168.1.5:9290/saas-api" },
    { name: "杨涛", url: "http://192.168.1.64:9290/saas-api" },
    { name: "正式", url: "https://sapi.tianzuoyun.com/saas-api" }
];
class ApiInfoExtension {
    constructor() {
        if (!this.current.url) {
            this.apiInfo = {
                ...this.apiInfo,
                current: {
                    ...apiList[0]
                }
            };
        }
    }

    get apiInfo() {
        const apiInfo: any = sessionStorage.getItem("apiInfo") || {};
        return apiInfo;
    }

    set apiInfo(val: any) {
        sessionStorage.setItem("apiInfo", val);
    }

    get current() {
        const apiInfo = this.apiInfo;
        return apiInfo.current || {};
    }

    get fixed() {
        const apiInfo = this.apiInfo;
        return !!apiInfo.fixed;
    }

    get drag() {
        const apiInfo = this.apiInfo;
        return apiInfo.drag || {};
    }

    get apiList() {
        const apiInfo = this.apiInfo;
        return (apiInfo.list || []).map((cur: any) => {
            return {
                ...cur,
                delete: true
            };
        });
    }

    get configList() {
        return apiList;
    }
}
export const apiInfoExtension: any = isDev ? new ApiInfoExtension() : {};

export const STATIC_URL = isDev ? staticUrl : process.env.VUE_APP_STATIC_API;
export const API_DEFAULT_CONFIG = {
    BaseURL: isDev
        ? apiInfoExtension.current.url
        : process.env.VUE_APP_SERVER_API,
    SocketUrl: isDev ? wsUrl : process.env.VUE_APP_WS_API,
    MockURL: ""
};
